package lumis.portal.device;

import java.util.Map;

import net.sourceforge.wurfl.core.CapabilityNotDefinedException;

/**
 * Represents the device informations
 * 
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class Device implements IDevice 
{
	public static final String DEVICE_ENTRY_KEY = "lum_device";
	
	private net.sourceforge.wurfl.core.Device wurlfDevice;
	
	/**
	 * Only constructor for this object
	 */
	Device (net.sourceforge.wurfl.core.Device wurlfDevice)
	{
		this.wurlfDevice=wurlfDevice;
	}
	
	
	/**
	 * Returns string representing the device's user agent
	 * @return string representing the device's user agent
	 * @throws Exception
	 */
	public String getUserAgent()
	{
		return wurlfDevice.getUserAgent();
	}
	
	/**
	 * Returns string representing the device's capability
	 * @param capability to be looked up
	 * @return string representing the device's capability
	 */
	public String getCapability(String capability)
	{
		try
		{
			return wurlfDevice.getCapability(capability);
		}
		catch (CapabilityNotDefinedException e)
		{
			return null;
		}
	}
	
	
	/**
	 * Returns the device's capability map.
	 * @return the device's capability map.
	 */
	@SuppressWarnings("unchecked")
	public Map<String, String> getCapabilities()
	{			
		return wurlfDevice.getCapabilities();
	}

	/**
	 * Returns a specific property of the context.
	 * 
	 * @param key the name of the context's property.
	 * @return a property of the context that match with the key.
	 * @since 6.0.0
	 */
	public Object getProperty(String key)
	{
		return getCapability(key);
	}
		
}
